<template>
  <div class="number-keyboard" @click.stop>
    <div class="keyboard-row">
      <button class="key-btn" @click="handleInput('7')">7</button>
      <button class="key-btn" @click="handleInput('8')">8</button>
      <button class="key-btn" @click="handleInput('9')">9</button>
      <button class="key-btn" @click="handleInput('0.25', 'Decimal')">¼</button>
      <button class="key-btn" @click="handleInput('0.5', 'Decimal')">½</button>
    </div>
    <div class="keyboard-row">
      <button class="key-btn" @click="handleInput('4')">4</button>
      <button class="key-btn" @click="handleInput('5')">5</button>
      <button class="key-btn" @click="handleInput('6')">6</button>
      <button class="key-btn" @click="handleInput('0.33', 'Decimal')">⅓</button>
      <button class="key-btn" @click="handleInput('0.67', 'Decimal')">⅔</button>
    </div>
    <div class="keyboard-row">
      <button class="key-btn" @click="handleInput('1')">1</button>
      <button class="key-btn" @click="handleInput('2')">2</button>
      <button class="key-btn" @click="handleInput('3')">3</button>
      <button class="key-btn" @click="handleInput('0.75', 'Decimal')">¾</button>
      <button class="key-btn" @click="handleInput('1.33', 'Decimal')">
        1⅓
      </button>
    </div>
    <div class="keyboard-row">
      <button class="key-btn" @click="handleInput('0')">0</button>
      <button class="key-btn" @click="handleInput('.')">.</button>
      <button class="key-btn" @click="handleInput('1.5', 'Decimal')">1½</button>
      <button class="key-btn" @click="handleInput('1.67', 'Decimal')">
        1⅔
      </button>
      <button class="key-btn" @click="handleDelete">退格</button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineEmits } from 'vue';

const emit = defineEmits(['input', 'delete']);

function handleInput(num: string, type?: string) {
  emit('input', num, type);
}
function handleDelete() {
  emit('delete');
}
</script>

<style scoped lang="scss">
.number-keyboard {
  background: white;
  border: 1px solid #e4e7ed;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.keyboard-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.key-btn {
  width: 50px;
  height: 40px;
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  background: #f8f9fa;
  color: #333;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  &:hover {
    background: #def4f3;
  }
}
.key-btn.delete-btn {
  width: 104px;
  background: #f56c6c;
  color: white;
  font-size: 14px;
}
</style>
